/*
 * NextAlgo.h
 *
 *  Created on: Jan 9, 2012
 *      Author: Netali
 */
#pragma once

#include "Algorithm.h"
#include "SystemView.h"
#include <list>
#include <map>
#include <string>
using namespace std;

class NextAlgor : public Algorithm
{
private:
		int exchangeNum;
		int limitExchg;
		double G; //G*rand_rm is no. of read miss for this time slice, G^2*rand_rm for the time slice before etc... 
		int L; //no. of time slices to look back

		void remove_from_ssd(ExtentStatsAlgo* ex);
		void remove_from_fc(ExtentStatsAlgo* ex);
		void remove_from_sata(ExtentStatsAlgo* ex);
		//bool existAndUpdateRandRm(ExtentEntry* ex, vector<ExtentEntry*>* list, double g);
		bool passLimitExchg(int currExchgNo);
		int removeExtentEntryFromDevice(ExtentStatsAlgo* ex);
		void sortedNTimeSlicesExtents(vector<ExtentEntry*>* list, int timeToDelete);
		//void removeFromSortedExtents(int timeToDelete, bool ifDelete);
		bool alreadyExistInSOrtedExtents(ExtentEntry* ex);
		bool alreadyExistInSOrtedExtentsFirstTime(ExtentEntry* ex, int TimeToDelete);
		bool alreadyExistInSOrtedExtentsLastTime(ExtentEntry* ex);
		void addToSorted(vector<ExtentEntry*>::iterator itList);
		ExtentStatsAlgo* popSsd();
		ExtentStatsAlgo* popFc();
		ExtentStatsAlgo* popSata();
        
public:
        NextAlgor(SystemView* sys, Writer* w, int limit, int sort_type, double constantG, int noTimeSlices, Parser* prs);
        virtual ~NextAlgor(void);
        void runAlgo(int iteration);
        double getHitRatio(void);
		int getExchangeNum(void);
		bool inSsd(ExtentStatsAlgo* ex);
		
};